/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rs_GUI;

import java.util.Date;
import javax.persistence.EntityManager;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import pojos.Playlist;
import pojos.Song;

/**
 *
 * @author KATERINA
 */
public class PlayListManagement extends javax.swing.JPanel {
    private RadioStationParentFrame frame;
    private EntityManager em;
    private Playlist playlist2;
    private boolean cancelSave; //Είναι true όταν έχουμε έρθει με το κουμπί μεταβολή, ενω
                                //το θέτουμε false όταν όταν έχουμε έρθει με το κουμπί εισαγωγή
    JMenuBar menu = new JMenuBar();
    JMenu  jMenu1 = new JMenu("Μενού");     
    
    /**
     * Creates new form PlayListManagement
     * @param frame
     * @param em
     * @param playlist2
     * @param cancelSave
     */
    public PlayListManagement(RadioStationParentFrame frame, EntityManager em, Playlist playlist2, boolean cancelSave) {
        this.frame = frame;
        this.em = em;
        this.playlist2 = playlist2;
        this.cancelSave = cancelSave;
        initComponents();
        durationTextField.setEditable(false);
        remainingTextField.setEditable(false);
        
        //Εισαγωγή της ημερομηνίας δημιουργίας
        creationDateDateChooser.setDate(playlist2.getCreation());
        
        JMenuItem saveAlbumItem = new JMenuItem("Αποθήκευση");
        saveAlbumItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveAlbumItemActionPerformed(evt);
            }
        });
        jMenu1.add(saveAlbumItem);
              
        JMenuItem cancelItem = new JMenuItem("Ακύρωση");
        cancelItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelItemActionPerformed(evt);
            }
        });
        jMenu1.add(cancelItem);
               
        menu.add(jMenu1);
        frame.setJMenuBar(menu);
    }
    
    private void saveAlbumItemActionPerformed(java.awt.event.ActionEvent evt) {                                           
        this.saveButtonActionPerformed(evt);
    }      
     
    private void cancelItemActionPerformed(java.awt.event.ActionEvent evt) {                                           
        this.cancelButtonActionPerformed(evt);
    } 
    
    
    //Μέθοδος για φιλτράρισμα της λίστας τραγουδιών ώστε να δείχνει μόνο τα τραγούδια 
    //της λίστας playlist2 
    public void getPlayListSongs(){
        songList.clear();
        for(Song sn : playlist2.getSongList()){
           songList.add(sn);
        }
    }
    
    //Μέθοδος υπολογισμού της συνολικής διάρκειας της λίστας.
    public void getDuration(){
        int drn = 0;
        for(Song sn : songList){
            drn = drn + sn.getDuration();
        }
        durationTextField.setText(Integer.toString(drn)+" sec");    
    }
    
    //Μέθοδος υπολογισμού υπολοιπόμενης ελάχιστης διάρκειας της λίστας.
    public void getRemainingDuration(){
        int drn2 = 0;
        for(Song sn : songList){
            drn2 = drn2 + sn.getDuration();
        }
        int remain = 1800 - drn2;
        if(remain >= 0){
            remainingTextField.setText(Integer.toString(remain)+" sec");
        }
        else {
            remainingTextField.setText(Integer.toString(0)+" sec");
        }
    }


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        songQuery = java.beans.Beans.isDesignTime() ? null : em.createQuery("SELECT s FROM Song s");
        songList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(songQuery.getResultList());
        playlist1 = playlist2;
        playListQuery = java.beans.Beans.isDesignTime() ? null : em.createQuery("SELECT p FROM Playlist p");
        playListList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : playListQuery.getResultList();
        jLabel1 = new javax.swing.JLabel();
        nameLabel = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        creationDateLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        songListTable = new javax.swing.JTable();
        newButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        durationLabel = new javax.swing.JLabel();
        durationTextField = new javax.swing.JTextField();
        remainingLabel1 = new javax.swing.JLabel();
        remainingTextField = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        creationDateDateChooser = new com.toedter.calendar.JDateChooser();
        cancelButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(610, 445));
        addHierarchyListener(new java.awt.event.HierarchyListener() {
            public void hierarchyChanged(java.awt.event.HierarchyEvent evt) {
                formHierarchyChanged(evt);
            }
        });
        addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
                formAncestorRemoved(evt);
            }
        });

        jLabel1.setText("ΦΟΡΜΑ ΔΙΑΧΕΙΡΙΣΗΣ ΛΙΣΤΑΣ");

        nameLabel.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        nameLabel.setText("Περιγραφή Λίστας *");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, playlist1, org.jdesktop.beansbinding.ELProperty.create("${name}"), jTextField1, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        creationDateLabel.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        creationDateLabel.setText("Ημερομηνία Δημιουργίας");

        jPanel2.setBackground(new java.awt.Color(204, 204, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Λίστα Τραγουδιών"));

        songListTable.setFont(new java.awt.Font("Comic Sans MS", 0, 13)); // NOI18N
        songListTable.getTableHeader().setReorderingAllowed(false);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, songList, songListTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${title}"));
        columnBinding.setColumnName("Τίτλος");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${albumid.artistid}"));
        columnBinding.setColumnName("Καλλιτέχνης");
        columnBinding.setColumnClass(pojos.Artist.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${albumid.musicgroupid}"));
        columnBinding.setColumnName("Συγκρότημα");
        columnBinding.setColumnClass(pojos.Musicgroup.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${duration}"));
        columnBinding.setColumnName("Διάρκεια (sec)");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(songListTable);
        if (songListTable.getColumnModel().getColumnCount() > 0) {
            songListTable.getColumnModel().getColumn(3).setPreferredWidth(0);
        }

        newButton.setText("ΕΙΣΑΓΩΓΗ");
        newButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newButtonActionPerformed(evt);
            }
        });

        deleteButton.setText("ΔΙΑΓΡΑΦΗ");
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        durationLabel.setText("Διάρκεια Λίστας:");

        durationTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                durationTextFieldActionPerformed(evt);
            }
        });

        remainingLabel1.setText("Πρέπει να βάλετε ακόμα τουλάχιστον:");

        remainingTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                remainingTextFieldActionPerformed(evt);
            }
        });

        jSeparator2.setForeground(new java.awt.Color(0, 0, 0));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(newButton)
                .addGap(18, 18, 18)
                .addComponent(deleteButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(remainingLabel1)
                            .addComponent(durationLabel))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(durationTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                            .addComponent(remainingTextField)))
                    .addComponent(jSeparator2)))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 574, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(durationLabel)
                            .addComponent(durationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(newButton)
                        .addComponent(deleteButton)))
                .addGap(1, 1, 1)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(remainingLabel1)
                    .addComponent(remainingTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        cancelButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        cancelButton.setForeground(new java.awt.Color(204, 0, 0));
        cancelButton.setText("ΑΚΥΡΩΣΗ");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        saveButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        saveButton.setText("ΑΠΟΘΗΚΕΥΣΗ");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nameLabel)
                            .addComponent(creationDateLabel))
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField1)
                            .addComponent(creationDateDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(40, 40, 40)
                        .addComponent(saveButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameLabel)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(creationDateDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(creationDateLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveButton)
                    .addComponent(cancelButton))
                .addContainerGap())
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void formAncestorRemoved(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_formAncestorRemoved
        // TODO add your handling code here:
    }//GEN-LAST:event_formAncestorRemoved

    private void formHierarchyChanged(java.awt.event.HierarchyEvent evt) {//GEN-FIRST:event_formHierarchyChanged
        getPlayListSongs();
        getDuration();
        getRemainingDuration();
    }//GEN-LAST:event_formHierarchyChanged

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        //Ακύρωση μετά από μεταβολή
        if (cancelSave){
            em.refresh(playlist2);
            cancelSave = false;
            
            frame.addPanelInMain(new PlayLists_MainPanel(frame, em));
        }
        //Μετά από εισαγωγή
        else {
            //Αναίρεση των αλλαγών που έγιναν στην playlist2
            em.remove(playlist2);
            cancelSave = false;
            em.getTransaction().commit();
            //Επαναφορά του γονέα
            frame.addPanelInMain(new PlayLists_MainPanel(frame, em));
        }
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        // Μήνυμα επιβεβαίωσης της αποθήκευσης
        Object[] options = {"Ναι","Όχι"};
        Integer choice = JOptionPane.showOptionDialog(this,
            "Θέλετε να αποθηκεύσετε τις αλλαγές;",
            "Επιβεβαίωση αλλαγών",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            options,
            options[0]);
        
        //Αν επιλεγεί το "Ναι"
        if (choice == JOptionPane.YES_OPTION){
            //Έλεγχος ότι δεν είναι κενά τα υποχρεωτικά πεδία
            if (playlist2.getName().equals("")) {
                JOptionPane.showMessageDialog(this, "Τα πεδία με αστερίσκο (*)"+
                    "\nείναι υποχρεωτικά."+
                    "\nΔεν γίνεται να μείνουν κενά", "ERROR",
                    JOptionPane.WARNING_MESSAGE);
                return;
            }
            
            //Έλεγχος για το αν υπάρχει ήδη λίστα με αυτό το όνομα στη ΒΔ
            for (Playlist play : playListList) {
                if (play != playlist2 && play.getName().equals(playlist2.getName())) {
                    JOptionPane.showMessageDialog(this,
                        "Υπάρχει λίστα με αυτό το όνομα.",
                        "Σφάλμα",
                        JOptionPane.WARNING_MESSAGE);
                    return;
                }
            }
            
            // Ελέγχουμε αν η λίστα έχει τραγούδια διάρκειας τουλάχιστον
            //μισής ώρας
            int dr = 0;
            for(Song s2 : songList){
                dr = dr + s2.getDuration();
            }
            if (dr < 1800) { 
                JOptionPane.showMessageDialog(this, 
                    "Η λίστα δεν μπορεί να έχει\n" 
                    + "διάρκεια μικρότερη της μισής ώρας (1800 sec).", 
                    "Σφάλμα",
                    JOptionPane.WARNING_MESSAGE);
                return;   
            }
            try {
                //Νέα δοσοληψία
                if (!em.getTransaction().isActive()) {
                    em.getTransaction().begin();
                }

                // Διαχείριση της ημερομηνίας δημιουργίας της λίστας
                Date creationDate = creationDateDateChooser.getDate();
                playlist2.setCreation(creationDate);
                
               
                //Ανανέωση των τραγουδιών της playlist2
                playlist2.getSongList().clear();
                for(Song song2 : songList){
                    playlist2.getSongList().add(song2);
                    if(!song2.getPlaylistList().contains(playlist2)){
                        song2.getPlaylistList().add(playlist2);
                    }
                }
                
                cancelSave = false;

                em.getTransaction().commit();
            }catch (Exception e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(null, "Σφάλμα βάσης...");
            }
            //Επαναφορά του γονέα
            frame.addPanelInMain(new PlayLists_MainPanel(frame, em));
        }
    }//GEN-LAST:event_saveButtonActionPerformed

    private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
        frame.addPanelInMain(new ListSong(frame, em, playlist2, cancelSave));
    }//GEN-LAST:event_newButtonActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        // Βάζουμε στη μεταβλητή row τη γραμμή που επιλέξαμε
        int row = songListTable.getSelectedRow();
        
        // Αν δεν έχουμε επιλλέξει κάτι τότε βγάλε μήνυμα λάθους
        if (songListTable.getSelectedRow() == -1) {
            JOptionPane.showMessageDialog(this, "Επιλέξτε ένα τραγούδι", 
                                           "ERROR",
                                           JOptionPane.WARNING_MESSAGE);
        }
        else {
            // Μήνυμα επιβεβαίωσης της διαγραφής
            Object[] options = {"Ναι","Όχι"};
            Integer choice = JOptionPane.showOptionDialog(this,
            "Αφαίρεση του επιλεγμένου τραγουδιού;",
            "Επιβεβαίωση διαγραφής",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            options,
            options[0]);
            
            //Αν επιλεγεί το "Ναι"
            if (choice == JOptionPane.YES_OPTION){
                //Βάλε στο s1 το τραγούδι
                Song s1 = songList.get(row);
                
                //Διαγράφουμε το τραγούδι από τη λίστα
                songList.remove(s1);
                
                //Αφαιρούμε το τραγούδι από τη λίστα τραγουδιών του playlist2
                playlist2.getSongList().remove(s1);
                getDuration();
                getRemainingDuration();
            }
        } 
    }//GEN-LAST:event_deleteButtonActionPerformed

    private void durationTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_durationTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_durationTextFieldActionPerformed

    private void remainingTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remainingTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_remainingTextFieldActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private com.toedter.calendar.JDateChooser creationDateDateChooser;
    private javax.swing.JLabel creationDateLabel;
    private javax.swing.JButton deleteButton;
    private javax.swing.JLabel durationLabel;
    private javax.swing.JTextField durationTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JButton newButton;
    private java.util.List<pojos.Playlist> playListList;
    private javax.persistence.Query playListQuery;
    private pojos.Playlist playlist1;
    private javax.swing.JLabel remainingLabel1;
    private javax.swing.JTextField remainingTextField;
    private javax.swing.JButton saveButton;
    private java.util.List<pojos.Song> songList;
    private javax.swing.JTable songListTable;
    private javax.persistence.Query songQuery;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
